package com.kitty.game.confirm.service.handler;

import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.equip.service.EquipService;
import com.kitty.game.role.model.Role;
import com.kitty.game.config.GameMap;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.confirm.model.FightSealBossConfirm;
import com.kitty.game.npc.message.RespAutoWalk;
import com.kitty.game.task.service.taskHandler.DigTreasureTaskHandler;
import com.kitty.game.team.message.ReqConfirmResult;
import com.kitty.game.utils.Const;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.mina.message.MessagePusher;
import org.apache.mina.core.session.IoSession;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;

@Component
public class FightSealBossConfirmHandler extends ConfirmHandler {
    @Override
    public void handleConfirmResult(Role role, ReqConfirmResult reqConfirmResult) {
        if ("1".equals(reqConfirmResult.getSelect())) {
            /**自动寻路到*/
            FightSealBossConfirm confirm = (FightSealBossConfirm)role.getConfirm();
            GameMap map = SpringUtils.getMapService().getMap(confirm.getFightMapId());
            RespAutoWalk respAutoWalk = new RespAutoWalk();
            respAutoWalk.setTaskName("");
            respAutoWalk.setDest(MessageFormat.format("#Z{0}#Z", map.getName()));
            MessagePusher.pushMessage(role, respAutoWalk);
        } else if ("0".equals(reqConfirmResult.getSelect())) {
           // SpringUtils.getBean(DigTreasureTaskHandler.class).checkContinueUseTreasureMapItem(role, Const.DIG_TREASURE_TYPE_SUPER,0);
            int digTreasureType = role.getActivity().getDigTreasureType();
            String name = Const.TREASURE_SUPER_SENIOR_ITEM_NAME;
            if (digTreasureType != Const.DIG_TREASURE_TYPE_SUPER_SENIOR){
                digTreasureType = Const.DIG_TREASURE_TYPE_SUPER;
                name = Const.TREASURE_SUPER_ITEM_NAME;
            }
            IoSession session = SessionUtils.getSession(role.getRoleId());
            if (session == null) {
                return;
            }
            RoleEquip roleEquip = SpringUtils.getBean(EquipService.class).getRoleEquipByName(session, name);
            if (roleEquip == null) {
                return;
            }
            SpringUtils.getBean(DigTreasureTaskHandler.class).useTreasureMapItem(role, (byte) digTreasureType, roleEquip);
        }
    }
}
